var app = new Vue({
	el: '#app',
	data: {
		infos:{
			user:globalData.userInfo
		},//用户的所有信息
		url:{
			getBasicQuestions: '/api/QuestionView/ViewBasicQuestions', //获取基本问题
			saveBasicQuestions: '/api/QuestionView/SaveBasicQuestionAnswers', //保存基本问题
			getSpecialQuestions: '/api/QuestionView/GetSpecialQuestions', //获取专属问题
			getQAUsers:'/api/UserQuestion/GetQAUsers',//获取用户列表
			getPageCurrencyRates:'/api/CurrencyRate/GetPageCurrencyRates', //获取货币种类
			getAllTDCategory:'/api/TreasureDiagnosisCategory/GetAllTDCategory', //获取所有资产类型
			getInternationalIntelligentAnalysis:'/api/Banner/GetInternationalIntelligentAnalysis', //跨境配置
			getTreasureDiagnosisImgs:'/api/Banner/GetTreasureDiagnosisImgs',//财富健康
		},
		type:0, //产品库，需求分析
		modelList:[],  //分类
		recommend_products:[], //推荐产品列表
		list_item:{}, //详情列表父item
		product_list_detail_show:{value:false}, //详情列表
		users:[], //用户列表
		user:globalData.getUserInfo(),
		CustomerID:'', //客户ID
		guide_map:[], //引导图
		children_data: {
			component_data: {
				nextQuestionID: "", //下题ID 
				selectedValue: "", //当前问题的值 
				isStop: false,
				hasTip: false,
				ShowMsg: ''
			},
			control9_10_data: {
				parent_value: [],
				control_out: {
					err: "",
					result: "",
					all_values: ""
				}
			},
			current_question: {},
			currentIndex: 0, //组件中当前题是第几题
			isShow: true, //tab内容、答题内容 切换
			question_step: 0, //答题步骤，基本、问答、推荐
			CustomerID: '', //客户ID
			AnswerItems: [], //答案列表
			answers: {
				name: '',
				mark: '',
				sex: '',
				birthday: '',
				birthplace: '',
				county: '',
				address: '',
				marriage: '',
				hasChild: '',
				occupation: '',
				workyear: '',
				isPep: '',
				industry: '',
				income: '',
				male: '',
				female: ''
			},
			evaluation_result:{}, //评估结果
		},
	},
	computed:{
		childs:function(){
			return (this.answers.male + ',' + this.answers.male)
		}
	},
	mounted: function() {
		var that = this;
		globalData.getTempToken(function(){			
			//获取用户列表
			that.showUsers(0,1)
		})

	},
	methods: {	
		showUsers:function(n,modelID){ //切换tab到用户列表
			var that = this
			if(!globalData.userIsLogin()){
				globalData.userIsLogin(null,true)
				return;
			}
			that.type = n
			globalData.utils.scrool_top()
			globalData.setStorage('modelID',modelID)
			this.getQAUsers() //获取用户
			//隐藏loading
			setTimeout(function(){
				$('.loading').hide()
			},50)
			
		},

		getAllTDCategory:function(){
			var that = this
			var data = {"CategoryType":""}
			globalData.ajaxPost(that.url.getAllTDCategory, data, function(res) {
				if(res.StatusCode == 200) {
					console.log(res)
					if(res.data){
						that.parent_info.my_questions = that.reorganization(res.data)
						console.log(that.parent_info.my_questions)
						console.log(res.data)
					}					
				}
			})
		},
		
		reorganization:function(data){
			var that = this
			if(!data){
				return {};
			}
			//三层结构			
			var out = [
						{
							CategoryTypeName: data[0].CategoryTypeName,
							CategoryType:data[0].CategoryType,
							types:[
								{
									"ParentID": data[0].ParentID,	
									"ParentAssetCategory": data[0].ParentAssetCategory,
									data:[
										{
											"ID": data[0].ID,
											"AssetCategory": data[0].AssetCategory,
											CurrencyID:that.parent_info.currencyRates[0].ID,
											AnswerValue1:''
										}
									]
								}
								
							]
						}
					]
				$(data).each(function(index,item){
					if(index>0){
						$(out).each(function(n,value){
							if(item.CategoryType==value.CategoryType){
								$(value.types).each(function(i,item_m){
									if(item_m.ParentID==item.ParentID){
										item_m.data.push({
											"ID": item.ID,
											"AssetCategory": item.AssetCategory,
											CurrencyID:that.parent_info.currencyRates[0].ID,
											AnswerValue1:''
										})
										return false;
									}else{
										if(i==value.types.length-1){
											value.types.push({										
												"ParentID": item.ParentID,	
												"ParentAssetCategory": item.ParentAssetCategory,
												data:[
													{
														"ID": item.ID,
														"AssetCategory": item.AssetCategory,												
														CurrencyID:that.parent_info.currencyRates[0].ID,
														AnswerValue1:''
													}
												]							
											})
										}
									}
								})
							}else{
								if(n==out.length-1){
									out.push(
										{
											CategoryTypeName: item.CategoryTypeName,
											CategoryType:item.CategoryType,
											types:[
												{
													"ParentID": item.ParentID,	
													"ParentAssetCategory": item.ParentAssetCategory,
													data:[
														{
															"ID": item.ID,
															"AssetCategory": item.AssetCategory,
															CurrencyID:that.parent_info.currencyRates[0].ID,
															AnswerValue1:''
														}
													]
												}
												
											]
										}
									)	
								}
							}
						})					
					}
					
				})
				return out;
		},
		reset_lunbo: function() {
			var mySwiper = new Swiper('.products_container', {
				loop: true,
				// 如果需要分页器
				pagination: '.products_pagination',
				// 如果需要前进后退按钮
				nextButton: '.products_next',
				prevButton: '.products_prev',
				loop: true,
				autoplay:3000,
				autoplayDisableOnInteraction : false,
			})
		},
		go_step_2: function(val) { //保存基本问题
			var that = this;
			var data = { 
				"ModelName": "高端生活",
				"UserAnswers": [{ "LoopTag": 1, "AnswerItems": val}]
				}
			console.log(data)
			globalData.ajaxPost(this.url.saveBasicQuestions, data, function(res) {
				if(res.StatusCode == 200) {
					//保存成功，返回客户id
					that.CustomerID = res.data
					console.log(res)
					that.step = 2
				}
			})
		},
		add_customer: function() {
			var that = this
			that.children_data.CustomerID = ''
			//初始化
			$.each(that.children_data.answers, function(name, value) {
				that.children_data.answers[name] = ''
			})
			console.log(that.children_data.answers)
			that.children_data.isShow = false
			that.children_data.question_step = 1
		},
		modify_userinfo:function(item){
			var that = this
			console.log(item)
			//赋值customer id
			that.children_data.CustomerID = item.ID
			that.children_data.isShow = false
			that.children_data.question_step = 1
		},
		change_customer:function(UserID){
			console.log(UserID)
			var that = this
			that.CustomerID = ''
			//初始化所有的通用数据
			$.each(that.answers,function(item,index){
				that.answers[item] = ''
			})
			console.log(that.answers)	
			that.parent_info.isShow = false
			that.parent_info.step_bar = 0
			globalData.utils.scrool_top()
		},
		go_user_list:function(){
			var that = this
			that.parent_info.isShow = true
		},
		//获取步骤二数据
		get_my_question:function(){
			var that = this
			var data = {
				"ModelID":"3",
				"QuestionType":2
			}
			globalData.ajaxPost(this.url.getSpecialQuestions, data, function(res) {				
				var data = res.data
				if(res.suc){
					console.log(data)
					that.AnswerOutputs = data[0].AnswerOutputs
					that.QuestionTitle = data[0].QuestionTitle
					console.log(that.AnswerOutputs)
				}
			})
		},
		getQAUsers: function() {
			var that = this
			globalData.ajaxPost(this.url.getQAUsers, null, function(res) {
				console.log(res)
				if(res.suc) {
					if(res.data.length==0){
						that.getRequirementAnalysisImgs()
					}
					that.users = res.data
				}
			})
		},
		getRequirementAnalysisImgs:function(){ //引导图
			var that = this
			if(that.type==0){
				var url = that.url.getTreasureDiagnosisImgs
			}else{
				var url = that.url.getInternationalIntelligentAnalysis
			}
			globalData.ajaxPost(url, null, function(res) {
				console.log(res)
				if(res.suc) {					
					console.log(res.data)
					that.guide_map = res.data
					$("#modal_photos").modal()
					setTimeout(function(){
						var mySwiper = new Swiper('.swiper-container', {
							loop: true,
							// 如果需要分页器
							pagination: '.swiper-pagination',
							freeMode:false,
							initialSlide:0,
							autoplay:3000,
							autoplayDisableOnInteraction : false,
							// 如果需要前进后退按钮
							nextButton: '.swiper-button-next',
							prevButton: '.swiper-button-prev'
						})
					},100)
				}
			})
		},
		show_list:function(id){
			console.log(id)
			this.product_list_detail_show.value = true
		},
		go_introduce:function(id){
			var obj = {
				id:id
			}
			var url = "product_intro.html"
			globalData.utils.setUrl(url,obj,true)
		},
		go_customers_list:function(){ //答题完毕，返回用户列表
			var that = this
			that.children_data.isShow = true
			that.children_data.question_step = 0
			that.getQAUsers() //获取用户
		}
	},
	filters: {
		cuttime: function(val) {
			var index = val.indexOf('T')
			var newval = val.replace(/-/g, '/').substring(0, index)
			return newval
		}
	}
})



